# Forked from Alpine to add systemd!

pkgname=plasma-workspace
pkgver=99996.2.5
_pkgver=6.2.5
pkgrel=0
pkgdesc="KDE Plasma Workspace"
# armhf blocked by qt6-qtdeclarative
arch="all !armhf !armv7"
url="https://kde.org/plasma-desktop/"
license="(GPL-2.0-only OR GPL-3.0-only) AND LGPL-2.1-or-later AND GPL-2.0-or-later AND MIT AND LGPL-2.1-only AND LGPL-2.0-or-later AND (LGPL-2.1-only OR LGPL-3.0-only) AND LGPL-2.0-only"
depends="
	accountsservice
	fprintd
	kactivitymanagerd
	kde-cli-tools
	kded
	kio-extras
	kirigami
	kirigami-addons
	kwin
	milou
	pipewire-session-manager
	plasma-integration
	qt6-qttools
	tzdata
	xdg-desktop-portal-gtk
	"
depends_dev="
	baloo-dev
	breeze-dev
	eudev-dev
	gpsd-dev
	icu-dev
	iso-codes-dev
	karchive-dev
	kauth-dev
	kcmutils-dev
	kcoreaddons-dev
	kcrash-dev
	kdbusaddons-dev
	kdeclarative-dev
	kded-dev
	kglobalaccel-dev
	kglobalacceld-dev
	kguiaddons-dev
	kholidays-dev
	ki18n-dev
	kiconthemes-dev
	kidletime-dev
	kio-dev
	kitemmodels-dev
	knewstuff-dev
	knotifications-dev
	knotifyconfig-dev
	kpackage-dev
	kparts-dev
	kpipewire-dev
	kquickcharts-dev
	krunner-dev
	kscreenlocker-dev
	kstatusnotifieritem-dev
	ksvg-dev
	ktexteditor-dev
	ktextwidgets-dev
	kunitconversion-dev
	kuserfeedback-dev
	kwayland-dev
	kwin-dev
	layer-shell-qt-dev
	libcanberra-dev
	libkexiv2-dev
	libkscreen-dev
	libksysguard-dev
	libplasma-dev
	libqalculate-dev
	networkmanager-qt-dev
	phonon-dev
	plasma-activities-stats-dev
	plasma-wayland-protocols
	plasma5support-dev
	prison-dev
	qcoro-dev
	qt6-qtpositioning-dev
	qt6-qtwayland-dev
	wayland-dev
	wayland-protocols
	zlib-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	kded
	kdoctools-dev
	libxtst-dev
	qt6-qttools-dev
	samurai
	xdotool
	systemd
	"
checkdepends="
	dbus
	xvfb-run
	"
case "$_pkgver" in
	*.90*) _rel=unstable;;
	*) _rel=stable;;
esac
subpackages="
	$pkgname-dbg
	$pkgname-dev
	$pkgname-libs
	$pkgname-doc
	$pkgname-lang
	$pkgname-zsh-completion
	$pkgname-systemd
	$pkgname-x11
	"
_repo_url="https://invent.kde.org/plasma/plasma-workspace.git"
source="https://download.kde.org/$_rel/plasma/$_pkgver/plasma-workspace-$_pkgver.tar.xz"
builddir="$srcdir/$pkgname-$_pkgver"

replaces="xdg-desktop-portal-kde<=6.1.5-r0"

# secfixes:
#   6.0.5.1:
#     - CVE-2024-36041


build() {
	# reduce size of debug syms
	CFLAGS="$CFLAGS -O2 -g1" CXXFLAGS="$CXXFLAGS -O2 -g1" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DPLASMA_X11_DEFAULT_SESSION=OFF \
		-DINSTALL_SDDM_WAYLAND_SESSION=OFF # Fails to get permissions to take control over tty

	# workaround for:
	# https://invent.kde.org/plasma/plasma-workspace/-/issues/132
	ninja -C build shell/qwayland-plasma-shell.h
	ninja -C build shell/wayland-plasma-shell-client-protocol.h

	cmake --build build
}

check() {
	local skipped_tests="(tasktoolstest"
	local tests="
		dbusmethodcalltest
		dbusservicewatchertest
		fetchinitialplayertest
		keystatetest
		klipper-testHistoryCycler
		klipper-testHistoryModel
		klippertest
		lockedtest
		mediakeystest
		mprisdeclarativetest
		servicerunnertest
		shelltest
		tasksmodeltest
		testdesktop
		testimagebackend
		testimagefinder
		testimagefrontend
		testimagelistmodel
		testimageproxymodel
		testmediametadatafinder
		testpackageimagelistmodel
		testrunnermodel
		testslidefiltermodel
		testslidemodel
		tst_triangleFilter
		waylandtasksmodeltest
		xwindowtasksmodeltest
		"
	case "$CARCH" in
		arm*|aarch64|ppc64le) tests="$tests calculatorrunnertest" ;;
	esac
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)"
	dbus-run-session -- xvfb-run -a ctest --test-dir build -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

x11() {
	pkgdesc="X11 desktop launcher for $pkgname"
	depends="xorg-server"
	install_if="$pkgname=$pkgver-r$pkgrel xorg-server"

	amove usr/bin/startplasma-x11 usr/share/xsessions/plasmax11.desktop
}

sha512sums="
228d183c9561cbf3d5630582b80c687868eaf420310010bd417de0e9f0ababaa4767805c1ce84f4eb3539ea32bfe6c2849b70d7ddd133f6095ab71f94f854dea  plasma-workspace-6.2.5.tar.xz
"
